package com.iscc.fake.dao.Impl;

import com.iscc.fake.dao.FormDao;
import com.iscc.fake.domain.Form;
import com.iscc.fake.util.DataSourceUtile;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class FormDaoImpl implements FormDao {
    @Override
    public int add(Form form) {
        int result = -1;
        Connection conn = null;
        PreparedStatement ps = null;
        String sql = "insert into form(date,uno,pprice,text,status,addno) values (?,?,?,?,?,?)";
        try {
            conn = DataSourceUtile.getConnection();
            ps = conn.prepareStatement(sql);
            ps.setString(1, form.getDate());
            ps.setInt(2, form.getUno());
            ps.setDouble(3, form.getPprice());
            ps.setString(4, form.getText());
            ps.setInt(5, form.getStatus());
            ps.setInt(6, form.getAddno());
            result = ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DataSourceUtile.closeReource(ps, conn);
        }
        return result;

    }

    @Override
    public int getNewId() {
        return 0;
    }
}